package com.wu.leetcode.leetcode897;

/**
 * Leetcode897-递增顺序查找树
 *
 * @author lynn
 * @date 2020/8/9 - 18:42
 */
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}

class Solution {
    TreeNode res;

    public TreeNode increasingBST(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode node = new TreeNode(0);
        res = node;
        inOrder(root);
        return node.right;
    }

    private void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }

        inOrder(root.left);

        res.left = null;
        res.right = root;
        res = res.right;
        inOrder(root.right);

    }
}

